package com.icart.repositories;


import com.icart.entities.CuCustcarEntity;
import com.icart.entities.CuCustinfoEntity;
import org.springframework.context.annotation.Scope;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;

@Repository
@Scope("prototype")
public interface CustcarRepository extends BaseRepository<CuCustcarEntity,Integer> {
    @Transactional
    @Query(nativeQuery = true,value = "update cu_custcar set regdate=?1 where custid=?2")
    @Modifying(clearAutomatically = true)
    Integer update(String regdate,Long custid);

    /*新增里程*/
    @Transactional
    @Query(nativeQuery = true,value = "update cu_custcar set curkilo=?1 where custid=?2")
    @Modifying(clearAutomatically = true)
    Integer updatekm(Long curkilo,Long custid);
    /*不是首次新增车系*/
    @Transactional
    @Query(nativeQuery = true,value = "insert into cu_custcar(custid,cartype,setdefault) values(?1,?2,0)")
    @Modifying(clearAutomatically = true)
    Integer insert(Long custid,String cartype);

    /*首次新增车系*/
    @Transactional
    @Query(nativeQuery = true,value = "insert into cu_custcar(custid,cartype,setdefault) values(?1,?2,1)")
    @Modifying(clearAutomatically = true)
    Integer firstinsert(Long custid,String cartype);

    /*删除车系*/
    @Transactional
    @Query(nativeQuery = true,value = "delete from cu_custcar where custcarid=?1 and custid=?2")
    @Modifying(clearAutomatically = true)
    Integer delete(Long custcarid,Long custid);

    /*设为默认前先全部设置为0*/
    @Transactional
    @Query(nativeQuery = true,value = "update cu_custcar set setdefault=0 where custid=?1")
    @Modifying(clearAutomatically = true)
    Integer setdefault(Long custid);

    /*设为默认前先全部设置为0后再设置点击的为默认*/
    @Transactional
    @Query(nativeQuery = true,value = "update cu_custcar set setdefault=1 where custid=?1 and custcarid=?2")
    @Modifying(clearAutomatically = true)
    Integer setdefault2(Long custid,Long custcarid);

    /*输入车牌号ajax存储*/
    @Transactional
    @Query(nativeQuery = true,value = "update cu_custcar set carno=?1 where custcarid=?2 and custid=?3")
    @Modifying(clearAutomatically = true)
    Integer savecarno(String carno,Long custcarid,Long custid);

    /*输入发动机号ajax存储*/
    @Transactional
    @Query(nativeQuery = true,value = "update cu_custcar set engineno=?1 where custcarid=?2 and custid=?3")
    @Modifying(clearAutomatically = true)
    Integer saveengineno(String engineno,Long custcarid,Long custid);

    /*输入vin ajax存储*/
    @Transactional
    @Query(nativeQuery = true,value = "update cu_custcar set vin=?1 where custcarid=?2 and custid=?3")
    @Modifying(clearAutomatically = true)
    Integer savevin(String vin,Long custcarid,Long custid);

    /*输入保险到期日ajax存储*/
    @Transactional
    @Query(nativeQuery = true,value = "update cu_custcar set insuexpirydate=?1 where custcarid=?2 and custid=?3")
    @Modifying(clearAutomatically = true)
    Integer saveinsuexpirydate(String insuexpirydate,Long custcarid,Long custid);

    /*输入保险公司ajax存储*/
    @Transactional
    @Query(nativeQuery = true,value = "update cu_custcar set insucomid=?1 where custcarid=?2 and custid=?3")
    @Modifying(clearAutomatically = true)
    Integer saveinsucomname(Long insucomid,Long custcarid,Long custid);

    /*输入违章城市查询ajax存储*/
    @Transactional
    @Query(nativeQuery = true,value = "update cu_custcar set regionid=?1 where custcarid=?2 and custid=?3")
    @Modifying(clearAutomatically = true)
    Integer saveregionid(String regionid,Long custcarid,Long custid);

    /*查到行驶证的信息，将其插入数据库*/
    @Transactional
    @Query(nativeQuery = true,value = "update cu_custcar set carno=?1,brand=?2,vin=?3,engineno=?4,regdate=?5,certdate=?6 where custcarid=?7 and custid=?8")
    @Modifying(clearAutomatically = true)
    Integer saveocr(String carno, String brand, String vin, String engineno,Date regdate,Date certdate, Long custcarid, Long custid);
}

